﻿@{
    ViewBag.Title = "充短信";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <link href="@Url.Content("~/content/css/kingprt.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/content/css/KingcensSet.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/content/css/font-awesome.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/Base/print.js")" type="text/javascript"></script> 
}

<div style="margin-top:10px;margin-left:33px;">
    <span style="font-size:12pt;">
        会员充值、消费时给会员发送提示短信
    </span>
</div>
<table width="1200px" style="margin-left:20px;">
    <tr>
        <td width="100px" height="40px" align="right" class="fonthsx">剩余短信：</td>
        <td colspan="2">
            <div id="SMSCount" name="SMSCount" class="fonthsx"></div>
        </td>
    </tr>
</table>
    <div style="width:800px;">
        <table style="width:400px;">
            <tr>
                <td width="80px" align="right"><span id="payAmount">短信签名：</span></td>
                <td width="200px">
                    <input name="FCorpName" id="FCorpName" class="mini-textbox" maxlength="20" style="width:200px;" value="" />
                </td>
                <td align="left">
                    <a class="mini-button" id="saveCorpName" name="saveCorpName" iconCls="icon-save" onclick="saveCorpName" plain="true">提交申请</a>
                </td>
            </tr>

            <tr style="height:40px;">
                <td width="80px" align="right"><span id="payAmount">短信数量：</span></td>
                <td width="200px">
                    <input name="FCount" class="mini-spinner" value="0" minValue="1250" maxValue="99999999" 　value="1250"
                           changeOnMousewheel="false" showbutton="false" style="width:200px;" selectOnFocus="true" onvaluechanged="changeCount" />
                </td>
                <td>
                    <font color="#FF0000" size ="2" >提交申请后请联系系统管理员，签名通过才可以发送短信。</font>
                </td>
            </tr>
            <tr style="height:40px;">
                <td width="80px" align="right"><span id="payPoint">赠送数量：</span></td>
                <td>
                    <input name="FSetAmount" class="mini-spinner" value="0" minValue="0" maxValue="1000000" value="0"
                           changeOnMousewheel="false" showbutton="false" style="width:200px;" readonly="readonly" />
                </td>
                <td></td>
            </tr>
            <tr style="height:40px;">
                <td width="80px" align="right"><span id="payAmount">充值金额：</span></td>
                <td width="200px">
                    <input name="FAmount" class="mini-spinner" value="0" minValue="0" maxValue="99999999" 　value="0"
                           changeOnMousewheel="false" showbutton="false" style="width:200px;" readonly="readonly" 　format="#,0.00" />
                </td>
                <td>
                    <a class="mini-button" id="Pay100" name="Pay100" onclick="SetPay(1250,0)" style="width:70px;margin-right:5px;">100元</a>
                    <a class="mini-button" id="Pay200" name="Pay200" onclick="SetPay(2500,100)" style="width:70px;margin-right:2px;">200元</a>
                    <a class="mini-button" id="Pay300" name="Pay300" onclick="SetPay(3750,150)" style="width:70px;margin-right:2px;">300元</a>
                </td>
            </tr>
            <tr style="height:40px;">
                <td></td>
                <td align="center">
                    <a class="mini-button" id="PayBtn" name="PayBtn" onclick="BillStart" style="width:70px;margin-right:10px;">充值</a>
                </td>
                <td></td>
            </tr>
        </table>
    </div>
<div style="        margin-left: 20px;
        font-size: 14px;">
    短信例子：
</div>
<div style="margin-left:50px;">
        尊敬客户,您尾号8888卡号消费-100.00元.可用储值:900.00元【XXXXX】
</div>
<div style="margin-left:20px;font-size:14px;">
    【XXXXX】是短信签名
</div>
<div style="margin-left:20px;font-size:14px;">
    签名为商户名称，需要更改时请注意.
</div>
<div style="margin-left:20px;font-size:14px;">
</div>
<div id="mpay" style="position:absolute;top:450px;width:205px;">
<div style="width:100%;height:30px;background-color:#299d33;font-size:16pt;text-align:center;vertical-align:middle;padding-top:5px;color:white;">
        微信扫描支付</div>
    <div style="padding-top:5px;padding-left:0px;">
        <div class="A4_verPrint">
            <iframe id="FMPAY" name="FMPAY" src=""  frameborder=0 width=210 height=210 marginheight=0 marginwidth=0 scrolling=no ></iframe>
        </div>
    </div>
</div>

<input type="hidden" value="@ViewBag.Price" id="Price" />

<script>
    mini.parse();
    $(function () {
        $.post("getSMSsign", { FSystemAppID: parent.window.getSystemAppID() }, function (data)
        {
            var mdata = mini.decode(data);
            if (mdata.data.length > 0) {
                mini.getbyName("FCorpName").setValue(mdata.data[0].FSmsSign);
                $("#SMSCount").html(mdata.data[0].FSMSQty);
                if (mdata.data[0].FCheckSignFlag == true)
                {
                    mini.getbyName("FCorpName").setEnabled(false);
                    mini.getbyName("saveCorpName").set({ visible: false });
                }
            }
        });

        $("#mpay").hide();
        var price = $("#Price").val();
        var count = mini.getbyName("FCount").getValue();
        mini.getbyName("FAmount").setValue(price * count);
        //$.post("getSMS_Count", { mjson: "[{'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
        //    $("#SMSCount").html(data);
        //});
    });

    function SetPay(smscount, setcount) {
        mini.getbyName("FCount").setValue(smscount);
        mini.getbyName("FSetAmount").setValue(setcount);
        changeCount();
    }

    function changeCount() {
        var count = mini.getbyName("FCount").getValue();
        if (count < 1250) {
            mini.alert("最少需1250条短信起");
            return;
        }
        var amount = count * $("#Price").val();
        mini.getbyName("FAmount").setValue(amount);
    }

    function BillStart() {
        var isnum = false;
        $.ajax({
            url: "CheckSmsSign",
            async: false,
            type: "POST",
            data: {
                mSystemAppID: parent.window.getSystemAppID()
            },
            success: function (data) {
                var ret = mini.decode(data);
                if (ret.status == "1")
                    isnum = true;
            }
        })
        //var isnum = /^\d+$/.test(mini.getbyName("FCorpName").getValue());
        if (!isnum) {
            //mini.alert("短信签名不能是数字");
            //return;
        }
        var json = "[{";
        json = json + "'type':22,";
        json = json + "'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]";

        mini.open({
            url: "../System/SMS_WXPay?SMSAmount=" + mini.getbyName("FAmount").getValue() + "&SMSCount=" + mini.getbyName("FCount").getValue()+"&mjson="+json,
            title: "微信支付", width: 600, height: 530,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {};
                data.AppID = parent.window.getSystemAppID();
                data.Amount = mini.getbyName("FAmount").getValue();
                data.iNum = mini.getbyName("FCount").getValue();
                data.type = 2;
                iframe.contentWindow.SetData(data);
            }
        });
    }

    function saveCorpName() {
        var json = "[{";
        json = json + "'FCorpName':'" + mini.getbyName("FCorpName").getValue() + "',";
        json = json + "'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]";

        $.post("SaveSign", { json: json }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1)
                mini.alert("保存完成");
            else
                mini.alert("保存失败," + ret.msg);
        });
    }
</script>